﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;
using System.Web.UI.HtmlControls;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZS_HZPersonControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            if (!base.Page.IsPostBack) {
                BindData();
            }
            CustomGridView CustomGridView1 = (CustomGridView)FindControl("CustomGridView1");
            CustomGridView1.OnLoadData += new EventHandler(CustomGridView1_OnLoadData);
            CustomGridView1.OnCancelClick += new EventHandler(CustomGridView1_OnCancelClick);
            CustomGridView1.OnComplelteClick += new EventHandler<CustomGridViewEventArgs>(CustomGridView1_OnComplelteClick);
            Button bt_query = (Button)FindControl("bt_query");
            bt_query.Click += new EventHandler(bt_query_Click);
        }

        protected void CustomGridView1_OnComplelteClick(object sender, CustomGridViewEventArgs e)
        {
            Label Label1 = (Label)FindControl("Label1");
            if (e == null)
            {
                BindData();
                Label1.Text = "请勾选人员！";
                return;
            }
            ProcesOnlyValue(e.MultiSelectKeys);
        }
        private void ProcesOnlyValue(DataKey[] keys)
        {
            string values = "";
            for (int i = 0; i < keys.Length; i++)
            {
                values += keys[i].Value.ToString() + "|";
            }
            if (values.Length > 0)
            {
                values = values.Remove(values.Length - 1);
            }
            InsertVas(values);
        }
        protected void InsertVas(string values)
        {
            string strpcid = base.Page.Request["PCID"];
            string strpnid = base.Page.Request["PNID"];
            _EluZSDataProvider.UpdatePCHRY(values, strpcid, strpnid);
            base.Page.Response.Write("<script>window.close();</script>");
        }
        protected void CustomGridView1_OnCancelClick(object sender, EventArgs e)
        {
            base.Page.Response.Write("<script>window.close();</script>");
        }
        protected void bt_query_Click(object sender, EventArgs e)
        {
            BindData();
        }
        protected void BindData() {
            string strPNID = HttpContext.Current.Request["PNID"];
            string strPCID = HttpContext.Current.Request["PCID"];
            CustomGridView CustomGridView1 = (CustomGridView)FindControl("CustomGridView1");
            DataTable dt = _EluZSDataProvider.GetBHZZJRY(strPNID, strPCID, GetSqlWhere());
            CustomGridView1.DataSource = dt;
            CustomGridView1.RecordCount = dt.Rows.Count;
            CustomGridView1.PageSize = 10;
            CustomGridView1.HideColName = "ID";
            CustomGridView1.DataKeyNames = new string[] { "ID" };
            CustomGridView1.DataBind();
        }
        protected void CustomGridView1_OnLoadData(object sender, EventArgs e)
        {
            BindData();
        }
        protected string GetSqlWhere() {
            string sqlWhere = string.Empty;
            string strType = HttpContext.Current.Request["TYPE"];
            TextBox txt_name = (TextBox)FindControl("txt_name");
            TextBox txtCZRName = (TextBox)FindControl("txtCZRName");
            TextBox txtFWZL = (TextBox)FindControl("txtFWZL");
            if (!string.IsNullOrEmpty(txt_name.Text.Trim()))
            {
                sqlWhere += " and 产权人 like '%" + txt_name.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txtCZRName.Text.Trim()))
            {
                sqlWhere += " and 承租人 like '%" + txtCZRName.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txtFWZL.Text.Trim()))
            {
                sqlWhere += " and 房屋坐落 like '%" + txtFWZL.Text.Trim() + "%'";
            }
            return sqlWhere;
        }
    }
}


